#!/usr/bin/env bash
# SPDX-License-Identifier: BSD-3-Clause
# Copyright 2016-2019, Intel Corporation
#
#
# rpmemd_config/TEST4 -- test for rpmemd config usage of user home dir
#

. ../unittest/unittest.sh

require_test_type medium
require_build_type debug
require_fs_type any

setup

RPMEMD=./rpmemd_config$EXESUFFIX

LOG=out${UNITTEST_NUM}.log
LOG_TEMP=out${UNITTEST_NUM}_temp.log
rm -f $LOG $LOG_TEMP

# use empty config to prevent loading config file from default location
# which may have nondefault configuration
EMPTY_CONFIG=$DIR/empty.conf
touch $EMPTY_CONFIG

function check_user_home_dir {
	expect_normal_exit $RPMEMD -c $EMPTY_CONFIG print_HOME_env
	cat $LOG >> $LOG_TEMP

	expect_normal_exit $RPMEMD -c $EMPTY_CONFIG --poolset-dir='\$HOME' print_HOME_env
	cat $LOG >> $LOG_TEMP

	expect_normal_exit $RPMEMD -c $EMPTY_CONFIG --poolset-dir=prefix'\$HOME' print_HOME_env
	cat $LOG >> $LOG_TEMP

	expect_normal_exit $RPMEMD -c $EMPTY_CONFIG --poolset-dir='\$HOME'stickysuffix print_HOME_env
	cat $LOG >> $LOG_TEMP

	expect_normal_exit $RPMEMD -c $EMPTY_CONFIG --poolset-dir='\$HOME'/suffix print_HOME_env
	cat $LOG >> $LOG_TEMP
}

HOME_BACKUP=$HOME
unset HOME

check_user_home_dir

export HOME=/user/home/path

check_user_home_dir

HOME=$HOME_BACKUP

$GREP -v rpmemd_config $LOG_TEMP > $LOG

check

pass
